<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Model\Cat;
use Session;
use Auth;

class IndexController extends Controller
{

    public function __construct()
    {

        $this->middleware('admin.login');
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        //获取认证用户的信息
        $users = Auth::User();
        //在session中存取用户信息
        Session::put('user',$users);
        //查询到所有的栏目
        $Cat = new Cat();
        //格式化取出所有数据
        $datas = $Cat->findAll();
//        dd($datas);
        //获取顶级栏目 即parent_id 为0
        $tops = $Cat->findSon($datas,0);
        /*//找子孙栏目   获取数据库数据信息树
        $sons = $this->cat->findGson($datas,0,0);*/
        return view('home.index')->with('datas',$datas)->with('tops',$tops);
//            ->with('sons',$sons);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //显示详情页
        return view('home.cat_show');
    }

}
